const mysql = require('mysql');
const connection = mysql.createConnection({
    host : '127.0.0.1',
    port : 3306,
    user : 'root',
    password : 'root',
    database : 'albx'
});

module.exports = {
     // 封装一个验证用户名和密码是否一致的方法
    verifyUsers(email,password,callback){
        let sql = `SELECT * FROM users WHERE email='${email}' AND \`password\`='${password}'`;
        connection.query(sql,(err,result)=>{
            callback(err,result[0]);
        });
    },
    // 封装获取所有用户的方法
    getAllUser(callback){
        let sql = 'SELECT * FROM users WHERE isDelete=0';
        connection.query(sql,(err,result)=>{
            callback(err,result);
        });
    },
    // 封装一个删除用户的方法
    deleteUserById(id,callback){
        let sql =   `UPDATE users SET isDelete=1 WHERE id=${id}`;
        connection.query(sql,(err,result)=>{
            callback(err,result);
        });
    },



}